var ctx;

var couponstate = "";

function setCtx(ctx){
	this.ctx = ctx;
}
function gotoPage(page){
	couponstate = ifNull($("#couponstate").val());
//	var couponid = ifNull($("#couponid").val());
	loadContent("/coupon/couponDetail?pNo="+ page+"&state="+ couponstate);
}

function gotoCouponDetailPage(page) {
	if(page == null){
		page = $(".inputclass").val();
	}
	var couponid = ifNull($("#couponid").val());
	loadContent("/coupon/couponDetail?pNo="+ page +"&state="+ couponstate);
}

function ifNull(mess){
	if(mess == null || mess == undefined){
		mess = "";
	}
	
	return mess;
}

//条件搜索菜单列表
function getCouponDetailList(){
	couponstate = $("#couponstate").val();
	var couponId = $("#couponid").val();
	var couponName = $("#couponName").val();
//	alert(couponstate);
	if(couponId == 1){
		loadContent("/coupon/couponDetail?pNo=1" + "&couponName="+ couponName + "&state="+ couponstate);
	}else{
		loadContent("/coupon/couponDetail?pNo=1"+"&couponId="+ couponId + "&couponName="+ couponName + "&state="+ couponstate);
	}
	
}


//导出优惠券发放和使用情况
function exportExcel() {
	couponstate = $("#couponstate").val();
	var couponId = ifNull($("#couponid").val());
	var couponName = ifNull($("#couponName").val());
	var total = ifNull($("#total").val());
	if(total >0) {
		if(couponId == 1){
			location.href=ctx +"/coupon/exportExcel?couponName=" + couponName + "&state=" + couponstate ;
		}else{
			location.href=ctx +"/coupon/exportExcel?couponId="+ couponId + "&couponName" + couponName + "&state=" + couponstate ;
		}
	} else {
		layer.msg("未获取到数据，无法导出...",{
			icon: 2,
			time: 2000 //2秒关闭（如果不配置，默认是3秒）
		});
	}
	
}
//
//function exportExcel() {
//	title = ifNull($("#title").val());
//	type = $("#infoType").val();
//	state = $("#state").val();
//	level = $("#level").val();
//	beginDate = $("#beginDate").val();
//	endDate = $("#endDate").val();
//	total = ifNull($("#total").val());
//	complainType = $("#complainType").val();
//	
//	//解决ie9以下placeholder与value重复的问题
//	if(title == $("#title").attr("placeholder")){
//		title = "";
//	}
//	if(beginDate == $("#beginDate").attr("placeholder")){
//		beginDate = "";
//	}
//	if(endDate == $("#endDate").attr("placeholder")){
//		endDate = "";
//	}
//	if(total >0 && checkDate()) {
//		location.href=ctx +"/complainInfo/exportExcel?title="+ title + "&state="+ state+ "&type="+ type+ "&complainType="+ complainType
//			+ "&level="+ level+ "&beginDate="+ beginDate+ "&endDate="+ endDate;
//	} else {
//		layer.msg("未获取到数据，无法导出...",{
//			icon: 2,
//			time: 2000 //2秒关闭（如果不配置，默认是3秒）
//		});
//	}
//	
//}